home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tk8.0 / tests / id.test < prev    next >
Encoding:
Text File  |  1997-08-15  |  2.5 KB  |  97 lines  |  [TEXT/ALFA]

  1. # This file is a Tcl script to test out the procedures in the file
  2. # tkId.c, which recycle X resource identifiers.  It is organized in
  3. # the standard fashion for Tcl tests.
  4. #
  5. # Copyright (c) 1995 Sun Microsystems, Inc.
  6. #
  7. # See the file "license.terms" for information on usage and redistribution
  8. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  9. #
  10. # SCCS: @(#) id.test 1.7 97/05/15 09:47:10
  11.  
  12. if {[info procs test] != "test"} {
  13.     source defs
  14. }
  15.  
  16. foreach i [winfo children .] {
  17.     destroy $i
  18. }
  19. wm geometry . {}
  20. raise .
  21.  
  22. test id-1.1 {WindowIdCleanup, delaying window release} {unixOnly} {
  23.     bind all <Destroy> {lappend x %W}
  24.     catch {unset map}
  25.     frame .f
  26.     set j 0
  27.     foreach i {a b c d e f g h i j k l m n o p q} {
  28.     toplevel .f.$i -height 50 -width 100
  29.     wm geometry .f.$i +$j+$j
  30.     incr j 10
  31.     update
  32.     set map([winfo id .f.$i]) .f.$i
  33.     set map([testwrapper .f.$i]) wrapper.f.$i
  34.     }
  35.     set x {}
  36.     destroy .f
  37.  
  38.     # Destroy events should have occurred for all windows.
  39.     set result [list [lsort $x]]
  40.  
  41.     set x {}
  42.     update idletasks
  43.     set reused {}
  44.     foreach i {a b c d e} {
  45.     set w .${i}2
  46.     frame $w -height 20 -width 100 -bd 2 -relief raised
  47.     pack $w
  48.     if [info exists map([winfo id $w])] {
  49.         lappend reused $map([winfo id $w])
  50.     }
  51.     set map([winfo id $w]) $w
  52.     }
  53.  
  54.     # No window ids should have been reused: stale Destroy events still
  55.     # pending in queue.
  56.     lappend result [lsort $reused]
  57.  
  58.     # Wait a few seconds, then try again;  ids should still not have
  59.     # been re-used.
  60.  
  61.     set y 0
  62.     after 2000 {set y 1}
  63.     tkwait variable y
  64.     foreach i {a b c} {
  65.     set w .${i}3
  66.     frame $w -height 20 -width 100 -bd 2 -relief raised
  67.     pack $w
  68.     if [info exists map([winfo id $w])] {
  69.         lappend reused $map([winfo id $w])
  70.     }
  71.     set map([winfo id $w])] $w
  72.     }
  73.  
  74.     # Ids should not yet have been reused.
  75.     lappend result [lsort $reused]
  76.  
  77.  
  78.     # Wait a few more seconds, to give ids enough time to be recycled.
  79.     set y 0
  80.     after 6000 {set y 1}
  81.     tkwait variable y
  82.     foreach i {a b c d e f} {
  83.     set w .${i}4
  84.     frame $w -height 20 -width 100 -bd 2 -relief raised
  85.     pack $w
  86.     if [info exists map([winfo id $w])] {
  87.         lappend reused $map([winfo id $w])
  88.     }
  89.     set map([winfo id $w])] $w
  90.     }
  91.  
  92.     # Ids should be reused now, due to time delay.  Destroy events should
  93.     # have been discarded.
  94.     lappend result [lsort $reused] [lsort $x]
  95. } {{.f .f.a .f.b .f.c .f.d .f.e .f.f .f.g .f.h .f.i .f.j .f.k .f.l .f.m .f.n .f.o .f.p .f.q} {} {} {.f.o .f.p .f.q wrapper.f.p wrapper.f.q} {}}
  96. bind all <Destroy> {}
  97.